package com.ssy.lingxi.product.common.enums;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品图片设置方式
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/29
 */
public enum ImageTypeEnum {

    All(1, "所有规格属性共用商品图片"),
    Each(2, "按规格属性设置商品图片");

    private Integer code;
    private String name;

    ImageTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getNameByCode(Integer code) {
        ImageTypeEnum typeEnum = Arrays.stream(ImageTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return typeEnum == null ? "" : typeEnum.getName();
    }

    public static Boolean contains(Integer code) {
        return Arrays.stream(ImageTypeEnum.values()).anyMatch(e -> e.getCode().equals(code));
    }
}
